<?php
/**
 * Created by PhpStorm.
 * User: mac
 * Date: 19/12/21
 * Time: 19:20
 */

namespace app\admin\controller;


use app\common\bean\GlobalBean;
use app\common\bean\ListMap;
use app\common\bean\OrderGoodsBean;
use app\common\controller\AdminController;
use app\common\enum\OrderGoodsStatusEnum;
use app\common\enum\OrderGoodsPayTypeEnum;
use app\common\enum\OrderGoodsTypeEnum;
use app\common\manage\OrderGoodsManage;
use app\common\utils\ExitJsonUtil;

class OrderGoods extends AdminController
{
    public function edit(){
        $orderGoodsBean = new OrderGoodsBean();
        $orderGoodsBean->setData(['id'=>$this->postParams['id']]);
        $orderGoodsBean->setStatus(OrderGoodsStatusEnum::HADCOMFIRM);
        OrderGoodsManage::getInstance()->edit($orderGoodsBean);
        ExitJsonUtil::getInstance()->exitData([]);
    }
    public function downloadImg(){
        $OrderGoodsBean = new OrderGoodsBean();
        $OrderGoodsBean->setData($this->getParams);
        $orderGoodsBean = OrderGoodsManage::getInstance()->getInfo($OrderGoodsBean);

        $localurl = OrderGoodsManage::getInstance()->downZip($orderGoodsBean, $this->getParams['start']);
        header("Location:{$localurl}");
    }
    public function orderGoodsList(){//商品订单
        $listMap = new ListMap();
        $listMap->setData($this->getParams);
        $listMap->setParameter(OrderGoodsBean::$storeId, 0);
        $orderListMap = OrderGoodsManage::getInstance()->getPaginatorList($listMap);

        $this->assign([
            'orderList'=>$orderListMap->getList(),
            'currentPage'=>$orderListMap->getCurrentPage(),
            'totalCount'=>$orderListMap->getTotalCount(),
            'statusSelect'=>OrderGoodsStatusEnum::getArrayName(),
            'statusPay'=>OrderGoodsPayTypeEnum::getArrayName(),
        ]);
        return $this->fetch();
    }
    public function info(){
        $orderGoodsBean = new OrderGoodsBean();
        $orderGoodsBean->setData($this->getParams);
        $orderGoodsBean->setParameter(OrderGoodsBean::$storeId, 0);
        $sarr = OrderGoodsManage::getInstance()->getSplit($this->getParams['id']);
        $orderGoodsBean = OrderGoodsManage::getInstance()->getInfo($orderGoodsBean);
        $this->assign([
            'orderGoods'=>$orderGoodsBean->getData(),
            'ogt'=>OrderGoodsTypeEnum::getArrayName(),
            'ogs'=>OrderGoodsStatusEnum::getArrayName(),
            'ogp'=>OrderGoodsPayTypeEnum::getArrayName(),
            'detail'=>OrderGoodsManage::getInstance()->detail($orderGoodsBean),
            'sarr'=>$sarr
        ]);
        return $this->fetch();
    }
}